/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package common;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 *
 * @author HP
 */
public class DBConnection {

    private static final String JNDI = "jtds/asm_demo";
    private static DataSource ds = null;

    public static Connection getConnection() {
        Connection cnn = null;
        try {
            Context ct = new InitialContext();
            ds = (DataSource) ct.lookup(JNDI);
            cnn = ds.getConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NamingException ex) {
            Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
        }

        return cnn;
    }
}
